﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebSite.Core;
using Common;

namespace WebSite
{
    public partial class ViewBabyGroup : BasePage
    {
        public override bool NeedLogin
        {
            get
            {
                return false;
            }
        }

        public int currentTeamID = 0;
        public Maticsoft.Model.CarrefourCover.Baby babyA = null;
        public string babyAHeadImage = null;
        public string babyBHeadImage = null;
        public string babyALiveImage1 = null;
        public string babyALiveImage2 = null;
        public string babyBLiveImage1 = null;
        public string babyBLiveImage2 = null;
        public Maticsoft.Model.CarrefourCover.Baby babyB = null;

        public Maticsoft.Model.CarrefourCover.Team curTeam = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            Maticsoft.BLL.CarrefourCover.Team teambll = new Maticsoft.BLL.CarrefourCover.Team();
            Maticsoft.BLL.CarrefourCover.Baby babybll = new Maticsoft.BLL.CarrefourCover.Baby();

            NavHelper.SetNavMenuSelectedIndex(1);
            NavHelper.SetNavStepCurrentStep(0);

            currentTeamID = StringHelper.Convert(Request["teamid"], 0);
            if (currentTeamID == 0)
            {
                AlertMessage("组队不存在", "/index.aspx");
            }

            curTeam = teambll.GetModel(currentTeamID);
            if (curTeam == null)
            {
                AlertMessage("组队不存在", "/index.aspx");
            }

            if (curTeam.Type >= 2)
            {
                Response.Redirect("ViewBabyGroup1112.aspx?teamid=" + currentTeamID);
            }


            babyA = babybll.GetModel(curTeam.BabyAId.Value);
            babyB = babybll.GetModel(curTeam.BabyBId.Value);

            // 获取生活照
            Maticsoft.BLL.CarrefourCover.Image imgbll = new Maticsoft.BLL.CarrefourCover.Image();
            babyAHeadImage = babyBHeadImage = babyALiveImage1 = babyALiveImage2 =
                babyBLiveImage1 = babyBLiveImage2 = "/images/BabyGroup/waitselect_200.png";

            if (babyA != null)
            {
                babyAHeadImage = babyA.BabyHeadImg;
                var liveImageA = imgbll.GetLiveImageByBabyID(babyA.Id);

                if (liveImageA.Count > 0)
                {
                    babyALiveImage1 = liveImageA[0].ImgUrl;
                }
                if (liveImageA.Count > 1)
                {
                    babyALiveImage2 = liveImageA[1].ImgUrl;
                }
            }

            if (babyB != null)
            {
                babyBHeadImage = babyB.BabyHeadImg;
                var liveImageB = imgbll.GetLiveImageByBabyID(babyB.Id);

                if (liveImageB.Count > 0)
                {
                    babyBLiveImage1 = liveImageB[0].ImgUrl;
                }
                if (liveImageB.Count > 1)
                {
                    babyBLiveImage2 = liveImageB[1].ImgUrl;
                }
            }
        }
    }
}